package util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateSessionFactoryUtil {
	private static SessionFactory sessionFactory;
	
	
	private  HibernateSessionFactoryUtil() {
		
	}
	
	static{
	 sessionFactory=new Configuration().configure().buildSessionFactory();
	}
	

	public static SessionFactory getSessionFactory(){
		return sessionFactory;
	}
	
	public static Session getSession(){
		return sessionFactory.openSession();
	}
	
	public static void closeSession(Session session){
		if(session!=null){
			if (session.isOpen()) {
				session.close();				
			}
		}
	}
}
